﻿package common.components.transition.transitions.tween
{
	
	import common.components.transition.events.TransitionEvent;
	import common.components.transition.transitions.Transition;
	import common.components.transition.transitions.TransitionRunner;
	
	import mx.controls.Image;
	import mx.effects.Fade;
	import mx.events.EffectEvent;
	
	public class Fade extends Transition {
	
		public function Fade(runner:TransitionRunner,image:Image,transTime:Number,stayTime:Number)
		{
			super(runner,image,transTime,stayTime);
		}
		
		override protected function transInStart() : void
		{
			super.transInStart();
			this.fadeInStart();
		}
		
		private function fadeInStart():void
		{
			var fade:mx.effects.Fade = new mx.effects.Fade(this.image);
			fade.alphaFrom = 0;
			fade.alphaTo = 1;
			fade.duration = 1500;
			fade.addEventListener(EffectEvent.EFFECT_END, onFadeInEnd);
			fade.play();
		}
		
		private function onFadeInEnd(evt:EffectEvent):void
		{
			this.dispatchEvent(new TransitionEvent(TransitionEvent.TRANS_IN_END));
		}
			
	}

}